package com.compass.doctor.ui.home.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.viewbinding.ViewBinding
import com.compass.doctor.callback.OnCustomButtonClick
import com.compass.doctor.databinding.LayoutCommentsItemBinding
import com.compass.doctor.databinding.LayoutLatestCommentsItemBinding
import com.compass.framework.adapter.BaseBindViewHolder
import com.compass.framework.adapter.BaseMultiItemAdapter
import com.compass.framework.ext.saveAs
import com.compass.framework.glide.setUrl
import com.compass.framework.glide.setUrlCircle
import com.compass.framework.model.Comment
import com.compass.framework.utils.DateUtils
import com.compass.framework.utils.ViewUtils
import com.compass.framework.utils.dpToPx

/**
 * Description： 最新评论adapter
 * Date:2023/12/24 13:29
 */
class LatestCommentsAdapter constructor(private var itemType: Int) :

    BaseMultiItemAdapter<Comment>() {

    private lateinit var onChatBottomClick: OnCustomButtonClick

    //1为首页布局 2为列表布局
    override fun getDefItemViewType(position: Int): Int {
        return itemType
    }

    fun setBottomCallBack(onChatBottomClick: OnCustomButtonClick) {
        this.onChatBottomClick = onChatBottomClick
    }

    override fun onBindDefViewHolder(
        holder: BaseBindViewHolder<ViewBinding>,
        item: Comment?,
        position: Int
    ) {
        if (item == null) return
        //  //1、待接诊， 2、已接诊 3、已完成
        when (holder.itemViewType) {
            1 -> {
                val binding = holder.binding.saveAs<LayoutLatestCommentsItemBinding>()
                binding.apply {
                    if (position==getData().size-1)  lineBottom.visibility=View.GONE  else lineBottom.visibility=View.VISIBLE
                    ivHead.setUrlCircle(item.patientAvatar)

                    tvName.text=item.patientName
                    tvContent.text=item.content
                    tvTime.text=DateUtils.getTimeDescriptionByDate(item.createTime)
                    ivCommunication.setUrl(item.journalismImg)
                    ViewUtils.setClipViewCornerRadius(ivCommunication, dpToPx(5))
                }
            }

            2 -> {
                val binding = holder.binding.saveAs<LayoutCommentsItemBinding>()
                 binding.apply {
                     tvTitle.text=item.journalismTitle
                     tvDiagnose.text="浏览 ${item.readNum}"
                     tvLike.text="点赞 ${item.likeNum}"
                     tvCommunication.setUrl(item.journalismImg)
                     ViewUtils.setClipViewCornerRadius(tvCommunication, dpToPx(5))
                     ivHead.setUrlCircle(item.patientAvatar)
                     tvName.text=item.patientName
                     tvContent.text=item.content
                     tvTime.text=DateUtils.getTimeDescriptionByDate(item.createTime)

                 }
            }


        }


    }


    override fun getViewBinding(
        layoutInflater: LayoutInflater,
        parent: ViewGroup,
        viewType: Int
    ): ViewBinding {
        return when (viewType) {
            1 -> {
                LayoutLatestCommentsItemBinding.inflate(layoutInflater, parent, false)
            }

            2 -> {
                LayoutCommentsItemBinding.inflate(layoutInflater, parent, false)
            }

            else -> {
                LayoutLatestCommentsItemBinding.inflate(layoutInflater, parent, false)
            }
        }

    }
}